package com.next.muscu.visual;

import java.awt.Dimension;
import java.awt.TextField;
import java.text.ParseException;

import javax.swing.Box;
import javax.swing.BoxLayout;
import javax.swing.JFormattedTextField;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.text.MaskFormatter;

import com.next.muscu.data.ExoType;
import com.next.muscu.data.MyDataObject;

public class VisualExoTypeSimplePanel extends AbstractVisualBasicEditorPanel
		implements IVisualBasicEditorPanel {


	ExoType data = null;
	JTextField idTextField = new JTextField();
	//JFormattedTextField codeTextField;
	JTextField codeTextField = new JTextField();
	JTextField nameTextField = new JTextField();

	VisualExoTypeSimplePanel() {
		buildGui();
	}

	VisualExoTypeSimplePanel(ExoType data) {
		this.data = data;
		buildGui();
	}

	void buildGui() {
	
		idTextField.setEditable(false);
		this.setLayout(new BoxLayout(this, BoxLayout.X_AXIS));
		this.add(Box.createRigidArea(new Dimension(20,0)));
		this.add(new JLabel("id : "));
		this.add(Box.createRigidArea(new Dimension(5,0)));
		this.add(idTextField);
		this.add(Box.createRigidArea(new Dimension(20,0)));
		this.add(new JLabel("code : "));
		this.add(Box.createRigidArea(new Dimension(5,0)));
		this.add(codeTextField);
		this.add(Box.createRigidArea(new Dimension(20,0)));
		this.add(new JLabel("Nom : "));
		this.add(Box.createRigidArea(new Dimension(5,0)));
		this.add(nameTextField);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see com.next.muscu.visual.VisualBasicEditorPanel#getData()
	 */
	/**
	 * @return
	 * @uml.property  name="data"
	 */
	public ExoType getData() {
		data.setCode(codeTextField.getText());
		data.setName(nameTextField.getText());
		data.setId(Integer.parseInt(idTextField.getText()));
		return data;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * com.next.muscu.visual.VisualBasicEditorPanel#setData(com.next.muscu.data
	 * .MyDataObject)
	 */
	public void setData(MyDataObject data) {
		if (data instanceof ExoType) {
			this.data = (ExoType) data;
			codeTextField.setText(this.data.getCode());
			nameTextField.setText(this.data.getName());
			idTextField.setText(this.data.getId().toString());
			this.validate();
		}
	}
}
